package com.duanxian;

import com.duanxian.controller.LoginView;
import com.duanxian.loader.AfterStartupLoader;
import de.felixroske.jfxsupport.AbstractJavaFxApplicationSupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

import java.util.List;

/**
 *
 */
@SpringBootApplication
@ComponentScan(basePackages = {"com.duanxian.controller","com.duanxian.dao","com.duanxian.service","com.duanxian.core","com.duanxian.loader"})
public class Main extends AbstractJavaFxApplicationSupport implements CommandLineRunner{

    private static Logger LOGGER = LoggerFactory.getLogger(Main.class);

    @Autowired
    private List<AfterStartupLoader> startupLoaderList;

    public static void main(String[] args) {
        LOGGER.info("application starting...");
        //如果需要自定义启动动画可以调用该方法的重载
        launchApp(Main.class, LoginView.class, args);
    }


    @Override
    public void init() throws Exception {
        LOGGER.info("application init...");
        super.init();
    }

    /**
     * 获取在初始化视图之前Spring应用程序上下文和JavaFX平台的完全初始化后调用。
     * 覆盖此方法作为钩子为您的应用程序添加特殊代码。
     * 特别是要添加AWT代码，通过调用GUIState.getSystemTray（）来修改系统托盘图标和行为。
     * By default noop.
     */
    @Override
    public void beforeInitialView() {

    }

    /**
     * 非web应用启动完成加载
     * @param strings
     * @throws Exception
     */
    @Override
    public void run(String... strings) throws Exception {
        if(startupLoaderList!=null&&!startupLoaderList.isEmpty()){
            startupLoaderList.forEach(afterStartupLoader -> {
                afterStartupLoader.load();
                LOGGER.info("AfterStartupLoader load ...");
            });
        }
    }
}
